package cn.iocoder.yudao.module.game.service.platformData;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.game.controller.admin.platformData.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.platformData.PlatformDataDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.game.dal.mysql.platformData.PlatformDataMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.game.enums.ErrorCodeConstants.*;

/**
 * 平台数据 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PlatformDataServiceImpl implements PlatformDataService {

    @Resource
    private PlatformDataMapper platformDataMapper;

    @Override
    public Long createPlatformData(PlatformDataSaveReqVO createReqVO) {
        // 插入
        PlatformDataDO platformData = BeanUtils.toBean(createReqVO, PlatformDataDO.class);
        platformDataMapper.insert(platformData);
        // 返回
        return platformData.getId();
    }

    @Override
    public void updatePlatformData(PlatformDataSaveReqVO updateReqVO) {
        // 校验存在
        validatePlatformDataExists(updateReqVO.getId());
        // 更新
        PlatformDataDO updateObj = BeanUtils.toBean(updateReqVO, PlatformDataDO.class);
        platformDataMapper.updateById(updateObj);
    }

    @Override
    public void deletePlatformData(Long id) {
        // 校验存在
        validatePlatformDataExists(id);
        // 删除
        platformDataMapper.deleteById(id);
    }

    private void validatePlatformDataExists(Long id) {
        if (platformDataMapper.selectById(id) == null) {
            throw exception(PLATFORM_DATA_NOT_EXISTS);
        }
    }

    @Override
    public PlatformDataDO getPlatformData(Long id) {
        return platformDataMapper.selectById(id);
    }

    @Override
    public PageResult<PlatformDataDO> getPlatformDataPage(PlatformDataPageReqVO pageReqVO) {
        return platformDataMapper.selectPage(pageReqVO);
    }

}